package com.example.lanou.mynews.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.example.lanou.mynews.R;
import com.example.lanou.mynews.application.MyApplication;
import com.example.lanou.mynews.beans.Adsdb;
import com.example.lanou.mynews.single.SingleMode;

import java.util.ArrayList;


/**
 * Created by dllo on 16/1/14.
 */
public class ScrollPagerHeadAdapter extends PagerAdapter {
    private int size = Integer.MAX_VALUE;
    private ArrayList<String> imgUrl;

    public ScrollPagerHeadAdapter(ArrayList<String> imgUrl) {
        this.imgUrl = imgUrl;
    }

    @Override
    public int getCount() {
        return size;
    }


    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.news_head_item, container, false);
        ImageView imageView = (ImageView) view.findViewById(R.id.news_head_iv);
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView,R.mipmap.ic_launcher, R.mipmap.ic_launcher);
        SingleMode.getImageLoader().get(imgUrl.get(position%imgUrl.size()), listener);
        container.addView(view);
        return view;
    }
}
